You can't use == to compare two C-style strings. For == to work, one of the strings must be a C++ string. To compare C-style strings, use strcmp (from <cstring>). Alternatively, make one of the strings a C++ string. Or, since you're really only comparing a single character, you could use == to compare the character.
Code:
// compare as C-strings (include <cstring>)
if (strcmp(argv[1], "\n") == 0)
// compare as C++-strings (include <string>)
if (argv[1] == string("\n"))
//or
if (string(argv[1]) == "\n")
//or
if (string(argv[1]) == string("\n"))
// compare a single character
if (argv[1][0] == '\n')
// this is not exactly the same since it's possible that the next character
// is not '\0', so to be exactly the same it would need to be
if (argv[1][0] == '\n' && argv[1][1] == '\0')
However, it's unusual (though not impossible) that a command-line string will consist solely of a newline character.
It's best to just assume it's a good filename if the parameter is present, then try opening the file and check for errors there.
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(int argc, char* argv[])
{
if (argc != 2)
{
cerr << "Usage: stats filename\n";
return 1;
}
fstream f(argv[1]);
if (!f) {
cerr << "stats: Can't open file " << argv[1] << '\n';
return 1;
}
return 0;
}